package com.dongdongshop.consumer;

import com.dongdongshop.service.PhoneService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RocketMQMessageListener(topic = "userRegisterPhoneCode",consumerGroup = "dd_phone")
public class PhoneConsumer implements RocketMQListener {

    private static final Logger logger = LoggerFactory.getLogger(PhoneConsumer.class);

    @Autowired
    private PhoneService phoneService;

    @Override
    public void onMessage(Object o) {
        List<String> list = (List<String>) o;
        String phone = list.get(0);
        String code = list.get(1);
        try {
           // phoneService.sendPhoneCode(phone,code);
            phoneService.sendPhoneCodeByHttpClient(phone,code);
            logger.info("执行成功");
        }catch (Exception e){
            logger.error("执行失败",e);
        }
    }
}
